import os
import cv2

result_dir = 'E:/datasets/background_reid_train/'
person_dir = 'E:/datasets/person_reid_train/'
persons = os.listdir(person_dir)


person_imgs = []

for j in persons:
    person_imgs.append(j)

fgbg = cv2.createBackgroundSubtractorKNN()

size = len(person_imgs)

for i in range(size):

    person_img = cv2.imread(person_dir + person_imgs[i])
    result = fgbg.apply(person_img)
    name = person_imgs[i]
    cv2.imwrite(result_dir + name, result)
